class Firewall {
  constructor(list = []) {
    this.whitelist = list;
  }

  middleware() {
    return (req, res, next) => {
      let referer = req.get("referer");
      if (req.method === "GET") {
        if (this.whitelist.length && !this.whitelist.includes(referer)) {
          res.status(403).send("拒绝访问");
          return;
        }
      }
      next();
    };
  }
}

export default Firewall;
